<?php

    if (!defined('BASEPATH'))
        exit('No direct script access allowed');

    if (!function_exists('make_google_map')) {

        /**
         * Create array of objects with coordinates
         * 
         * @param   array   $items  The array of objects
         * 
         * @return  array
         */
        function make_google_map($items) {
            $gmap = array();

            foreach ($items as $v):

                if (isset($v->object_x_coordinate) && $v->object_x_coordinate != '' && isset($v->object_y_coordinate) && $v->object_y_coordinate != ''):

                    // Home, searchPReview, serch
                    if (isset($v->lowest_price)) {   // Home page
                        $price = $v->lowest_price;
                        $room_id = $v->lowest_price_room_id;
                    } else if (isset($v->rooms[0]->selling_price)) {   // Search
                        $price = $v->rooms[0]->selling_price;
                        $room_id = $v->rooms[0]->room_ID;
                    } else {        // Search Prevew
                        $price = 0;
                        $room_id = $v->rooms[0]->room_ID;
                    }

                    $gmapSTD = new stdClass;
                    $gmapSTD->ID = $v->object_ID;
                    $gmapSTD->name = $v->object_name;
                    $gmapSTD->type = $v->object_type_ID;
                    $gmapSTD->destination = $v->destination_name;
                    $gmapSTD->address = strip_tags($v->object_address, '<b><strong><em><i>');
                    $gmapSTD->stars = isset($v->object_number_of_stars) && $v->object_number_of_stars != "" ? $v->object_number_of_stars : 0;
                    $gmapSTD->photo_path = $v->photo_path;
                    $gmapSTD->photo_name = $v->photo_name;
                    $gmapSTD->photo_title = isset($v->photo_title) ? $v->photo_title : "";
                    $gmapSTD->x = $v->object_x_coordinate;
                    $gmapSTD->y = $v->object_y_coordinate;
                    if (function_exists('lang_url'))
                        $gmapSTD->link = lang_url('accommodation/' . URLify::filter($v->object_name) . '-' . $v->object_ID . "?preview=1&room_id=" . $room_id . "&currency=" . currency_sign());
                    else
                        $gmapSTD->link = base_url('accommodation/' . URLify::filter($v->object_name) . '-' . $v->object_ID . "?preview=1&room_id=" . $room_id . "&currency=" . currency_sign());

                    $gmapSTD->image = HOST_URL_HOTELS . $v->photo_path . '/thumb_88x88/' . $v->photo_name;
                    $gmapSTD->price = $price;
                    $gmapSTD->reviews = $v->total_reviews;
                    $gmapSTD->score = $v->avg_reviews_score;


                    $gmap[] = $gmapSTD;

                endif;

            endforeach;

            return $gmap;
        }

    }
?>
